package com.ruoyi.project.mahjong.controller;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.redis.RedisCache;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.mahjong.domain.TRechargeMoney;
import com.ruoyi.project.mahjong.service.ITRechargeMoneyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 充值赠送点数Controller
 *
 * @author ruoyi
 * @date 2023-10-10
 */
@RestController
@RequestMapping("/mahjong/money")
public class TRechargeMoneyController extends BaseController
{
    @Autowired
    private RedisCache redisCache;
    @Autowired
    private ITRechargeMoneyService tRechargeMoneyService;

    /**
     * 查询充值赠送点数列表
     */

    @GetMapping("/list")
    public TableDataInfo list(TRechargeMoney tRechargeMoney)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long shopId = redisCache.getCacheObject(Constants.SHOP_SUF + user.getUserId());
        tRechargeMoney.setBak2(String.valueOf(shopId));
        startPage();
        List<TRechargeMoney> list = tRechargeMoneyService.selectTRechargeMoneyList(tRechargeMoney);
        return getDataTable(list);
    }


    @GetMapping("/listAllMoney/getall")
    public AjaxResult listMoney(TRechargeMoney tRechargeMoney)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long shopId = redisCache.getCacheObject(Constants.SHOP_SUF + user.getUserId());
        tRechargeMoney.setBak2(String.valueOf(shopId));
        List<TRechargeMoney> list = tRechargeMoneyService.selectTRechargeMoneyList(tRechargeMoney);
        return AjaxResult.success(list);
    }
    /**
     * 导出充值赠送点数列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:money:export')")
    @Log(title = "充值赠送点数", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TRechargeMoney tRechargeMoney)
    {
        List<TRechargeMoney> list = tRechargeMoneyService.selectTRechargeMoneyList(tRechargeMoney);
        ExcelUtil<TRechargeMoney> util = new ExcelUtil<TRechargeMoney>(TRechargeMoney.class);
        return util.exportExcel(list, "money");
    }

    /**
     * 获取充值赠送点数详细信息
     */
    @PreAuthorize("@ss.hasPermi('mahjong:money:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tRechargeMoneyService.selectTRechargeMoneyById(id));
    }

    /**
     * 新增充值赠送点数
     */
    @PreAuthorize("@ss.hasPermi('mahjong:money:add')")
    @Log(title = "充值赠送点数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRechargeMoney tRechargeMoney)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long shopId = redisCache.getCacheObject(Constants.SHOP_SUF + user.getUserId());
       tRechargeMoney.setBak2(shopId.toString());
        return toAjax(tRechargeMoneyService.insertTRechargeMoney(tRechargeMoney));
    }

    /**
     * 修改充值赠送点数
     */
    @PreAuthorize("@ss.hasPermi('mahjong:money:edit')")
    @Log(title = "充值赠送点数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRechargeMoney tRechargeMoney)
    {    SysUser user = SecurityUtils.getLoginUser().getUser();
        Long shopId = redisCache.getCacheObject(Constants.SHOP_SUF + user.getUserId());
        tRechargeMoney.setBak2(shopId.toString());
        return toAjax(tRechargeMoneyService.updateTRechargeMoney(tRechargeMoney));
    }

    /**
     * 删除充值赠送点数
     */
    @PreAuthorize("@ss.hasPermi('mahjong:money:remove')")
    @Log(title = "充值赠送点数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tRechargeMoneyService.deleteTRechargeMoneyByIds(ids));
    }
}
